Failed Conditions
Push — master ( f5e7b3...711045 )
by Yo
01:30
created

seqAnyway.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 9.4285
1
"use strict";
2
3
/**
4
 * @param {Array<callback>} callbackList
5
 *
6
 * @returns {Promise<value>} Return a promise resolved even if one or more callbacks have failed.
7
 *                           Callbacks will be called one by one in the order returned by callbackList.map
8
 *                           Resolved value is an object containing resolvedList and rejectedList
9
 *                            - resolvedList will contains successful callback returned value ordered by callback index
10
 *                            - rejectedList will contains rejected callback error ordered by callback index
11
 */
12
module.exports = (callbackList) => {
13
    const resolvedList = [];
14
    const rejectedList = [];
15
16
    return new Promise(resolve => {
17
        callbackList.map((callback, index) => {
18
            try {
19
                resolvedList[index] = callback();
20
            } catch (e) {
21
                rejectedList[index] = e;
22
            }
23
        });
24
25
        resolve({resolvedList, rejectedList});
26
    });
27
};
28